package com.leyou.order.controller;

import com.leyou.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
public class PayController {

    @Autowired
    private OrderService orderService;

    /**
     * @ResponseBody注解在有对应jar包支持的前提下，
     * 可以直接将JavaBean或者Map转成json或者xml，默认是json。
     * 如果要指定返回的数据类型，用produces="application/xml"
     */
    @PostMapping(value = "/pay/wx/notify", produces="application/xml")
    public Map<String, String> getWxNotify(@RequestBody Map<String, String> notifyParam){
        log.info("【微信支付结果通知】开始处理！");
        //验证支付信息是否正确
        orderService.getWxNotify(notifyParam);
        //按照微信要求返回结果
        Map<String, String> resultMap = new HashMap<>();
        resultMap.put("return_code", "SUCCESS");
        resultMap.put("return_msg", "OK");
        log.info("【微信支付结果通知】成功结束并告知微信！");
        return resultMap;
    }

}
